#include "gofgame/jumpdown/sprite/ErraticPedal.h"
#include "gofgame/jumpdown/util/AnimateBuilder.h"
#include "gofgame/jumpdown/util/objective-c.h"
#include "SimpleAudioEngine.h"

using namespace gofgame::jumpdown::sprite;
using namespace gofgame::jumpdown::util;
using namespace gofgame::jumpdown;
using namespace CocosDenshion;

ErraticPedal::ErraticPedal() {
}

ErraticPedal::~ErraticPedal() {
	std::cout << "erraticPedal" << std::endl;
}

bool ErraticPedal::init() {
	if(!Pedal::initWithSpriteFrameName("nor.png")) {
		delete this;
		return false;
	}
	this->initAnimate();
	return true;
}

void ErraticPedal::initAnimate(){
	this->flipAnnmate = 
		AnimateBuilder("JumpDown.plist")
		.add("nor.png")
		.add("nor2.png")
		.add("nor3.png")
		.add("nor4.png")
		.add("nor5.png")
		.add("nor.png")
		.buildAnimate(0.1F);
}

void ErraticPedal::playFlip() {
	this->stopAction(this->flipAnnmate);
	this->runAction(this->flipAnnmate);
}

ErraticPedal *ErraticPedal::createErraticPedal(){
	ErraticPedal *erraticPedal;
	if (oc_new<ErraticPedal>(&erraticPedal)) {
		erraticPedal->autorelease();
	}
	return erraticPedal;
}

bool ErraticPedal::onTouchHero(Hero* hero) {
	SimpleAudioEngine::sharedEngine()->playEffect("g2fake.wav");
	this->playFlip();
	hero->recoverHp();
	return false;
}